package org.ligson.springbootrestdao.service;

import lombok.extern.slf4j.Slf4j;
import org.ligson.springbootrestdao.dao.UserDao;
import org.ligson.springbootrestdao.entity.User;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Service
@Lazy(value = false)
@Slf4j
public class UserServiceImpl implements UserService {
    private final UserDao userDao;

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @PostConstruct
    public void init() {
        List<User> userList = new ArrayList<>();
        for (int i = 0; i < 200; i++) {
            User user = new User();
            user.setName("test" + i);
            log.debug("insert.............");
            //   userDao.save(user);
            userList.add(user);
            log.debug("insert.............after");

        }
        userDao.saveAll(userList);
    }
}
